package kr.saeildamil.androidstudty.ch08;

import java.util.ArrayList;

import kr.saeildamil.androidstudty.ch07.MyView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class FreeLine extends Activity {
	MyView mv;
	ArrayList<VertexEntity>arList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mv=new MyView(this);
		setContentView(mv);
		arList=new ArrayList<VertexEntity>();
	}
	
	public class Myview extends View{
		Paint mPaint;
		public Myview(Context context) {
			super(context);
			mPaint=new Paint();
			mPaint.setColor(Color.BLACK);
			mPaint.setStrokeWidth(3);
			mPaint.setAntiAlias(true);
			// TODO Auto-generated constructor stub
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			canvas.drawColor(Color.LTGRAY);
			
			for(int i=0; i<arList.size(); i++){
				canvas.drawLine(arList.get(i-1).getX(), arList.get(i-1).getY(),
						arList.get(i).getX(),arList.get(i).getY(),mPaint);
			}
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				Toast.makeText(FreeLine.this, "ACTION_DOWN", 1000).show();
				arList.add(new VertexEntity(event.getX(), event.getY(), false));
				return true;
			}
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				Toast.makeText(FreeLine.this, "ACTION_MOVE", 1000).show();
				arList.add(new VertexEntity(event.getX(), event.getY(), false));
				invalidate();
				return true;
			}
			return false;

		}
	
	}
}

